package com.eyes.ds.display;

import android.app.Presentation;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Display;
import android.widget.VideoView;

import com.eyes.ds.R;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;

import java.io.IOException;
import java.util.Objects;

/**
 * Author Jayy.Lucas
 * Email: eyes.left@qq.com
 * Date: 2018/9/17
 * Time: 上午9:57
 */
public class VideoShow extends Presentation {
    private String uri;

    public VideoShow(Context context, Display display,
                   String uri) {
        super(context, display);
        this.uri = uri;
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Be sure to call the super class.
        super.onCreate(savedInstanceState);
        // Inflate the layout.
        setContentView(R.layout.video);
//        final VideoView mVv = findViewById(R.id.video);
        // 播放在线视频
//        mVv.setVideoURI(Uri.parse(uri));
        PlayerView videoView = findViewById(R.id.video);
        SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getContext());
        videoView.setPlayer(player);
        // Produces DataSource instances through which media data is loaded.
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Kao"));
        // This is the MediaSource representing the media to be played.
        MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(uri));
        // Prepare the player with the source.
        player.prepare(videoSource);
        player.setPlayWhenReady(true);
    }

}
